package com.boronstream.istar.model;

import java.util.Iterator;

import org.json.JSONException;
import org.json.JSONObject;

public class AppInfo extends PlayObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// private String appName;
	// private String packageName;
	// private String appVersion;
	// private String appVersionCode;
	// private boolean isUserApp;
	// private long firstInstallTime;
	// private long lastUpdateTime;

	private long _id;
	private String device_id;
	private String app_name;
	private String package_name;
	private String version_name;
	private long version_code;
	private String app_type;
	private long install_time;
	private long update_time;

	public AppInfo() {

	}

	public AppInfo(JSONObject jsonObject) {

		if (jsonObject == null) {
			return;
		}

		// Step1.Get all the keys list
		@SuppressWarnings("unchecked")
		Iterator<String> keysIterator = jsonObject.keys();

		while (keysIterator.hasNext()) {
			String key = keysIterator.next();
			try {
				initParamWithJsonAndKey(jsonObject, key);
			} catch (Exception e) {
			}
		}

	}

	public long get_id() {
		return _id;
	}

	public void set_id(long _id) {
		this._id = _id;
	}

	public String getDevice_id() {
		return device_id;
	}

	public void setDevice_id(String device_id) {
		this.device_id = device_id;
	}

	public String getApp_name() {
		return app_name;
	}

	public void setApp_name(String app_name) {
		this.app_name = app_name;
	}

	public String getPackage_name() {
		return package_name;
	}

	public void setPackage_name(String package_name) {
		this.package_name = package_name;
	}

	public String getVersion_name() {
		return version_name;
	}

	public void setVersion_name(String version_name) {
		this.version_name = version_name;
	}

	public long getVersion_code() {
		return version_code;
	}

	public void setVersion_code(long version_code) {
		this.version_code = version_code;
	}

	public String getApp_type() {
		return app_type;
	}

	public void setApp_type(String app_type) {
		this.app_type = app_type;
	}

	public long getInstall_time() {
		return install_time;
	}

	public void setInstall_time(long install_time) {
		this.install_time = install_time;
	}

	public long getUpdate_time() {
		return update_time;
	}

	public void setUpdate_time(long update_time) {
		this.update_time = update_time;
	}

	public JSONObject toJsonObject() {
		JSONObject jsonObject = new JSONObject();
		try {
			jsonObject.put("_id", get_id());
			jsonObject.put("device_id", getDevice_id());
			jsonObject.put("app_name", getApp_name());
			jsonObject.put("package_name", getPackage_name());
			jsonObject.put("version_name", getVersion_name());
			jsonObject.put("version_code", getVersion_code());
			jsonObject.put("app_type", getApp_type());
			jsonObject.put("install_time", getInstall_time());
			jsonObject.put("update_time", getUpdate_time());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}

	@Override
	public void initParamWithJsonAndKey(JSONObject jsonObject, String key)
			throws JSONException {
		// if ("name".equals(key)) {
		// this.setAppName(jsonObject.getString(key));
		// } else if ("pkgname".equals(key)) {
		// this.setPackageName(jsonObject.getString(key));
		// } else if ("version".equals(key)) {
		// this.setAppVersion(jsonObject.getString(key));
		// } else if ("first_install_time".equals(key)) {
		// this.setFirstInstallTime(jsonObject.getLong(key));
		// }
	}

}
